package com.hopedove.utils

sealed class LoginValidationResult(val message: String? = null) {

    class Ok(message: String? = null) : LoginValidationResult(message)
    class Failed(message: String) : LoginValidationResult(message)
}

class LoginValidation {

    fun validate(username: String?, password: String?): LoginValidationResult {
        var failed: LoginValidationResult.Failed? = checkIsEmpty(username, password)
        if (failed != null) return failed

        val pwd = password!!
        failed = validatePassword(pwd)
        if (failed != null) return failed

        return LoginValidationResult.Ok()
    }

    private fun checkIsEmpty(username: String?, password: String?): LoginValidationResult.Failed? {
        return when {
            username.isNullOrEmpty() -> LoginValidationResult.Failed("用户名为空")
            password.isNullOrEmpty() -> LoginValidationResult.Failed("密码为空")
            else -> null
        }
    }

    // 密码暂不处理
    private fun validatePassword(password: String): LoginValidationResult.Failed? = null
}